<?
class Mlt
	{
		var $aLst;
		var $oPaging;
		var $cTitle;
		var $cSummary;
		var $cOptions = '';
		var $aColumns= array();
		var $cListActions = "";
		var $aTab = array();
		// Propiedades para los Diretorios
		var $nqCols = 2;
		var $bFieldTitle = true;
		var $cUrlBase;
		var $cClassContainer;
		var $nCalendarView = CALENDAR_WEEK;
		
	function setExpandAll( $bOn = true )
		{
			$this->bAutoExpand = $bOn;
		}
	function setClassContainer( $cClassContainer)
		{
			$this->cClassContainer = $cClassContainer;
			$cOptions = getParam( PARAM_OPTIONS . '_' . $this->cClassContainer );
			if ( $cOptions ) $this->cOptions = $cOptions;
			$this->oPaging->setUrlBase( $this->cUrlBase);
			$this->oPaging->setClassContainer( $cClassContainer);
		}
	function getUrlBase()
		{
			return $this->cUrlBase;
		}
	function setUrlBase()
		{
			$cClassName = strtolower(get_class($this));
			$this->cUrlBase = '?' . PARAM_MODULE . '=' . $this->oModule->cModule . '&amp;' . PARAM_ACTION . '=' . $this->oModule->cAction  . '&amp;' . PARAM_REFRESH . '=class&amp;' . PARAM_CLASS . '=' . $cClassName .'&amp;' . PARAM_TARGET . '=' . $this->oModule->getTarget() ;
			if ( $this->cClassContainer != $cClassName ) $this->cUrlBase .=  "&amp;" . PARAM_CONTAINER . '=' . $this->cClassContainer;
			$this->cUrlBase .=  "&amp;" . $this->getFieldString();
			$this->oPaging->setUrlBase( $this->cUrlBase);
		}
	function addListAction( $cAction, $cParametros = '' , $cAccessKey = '', $ncModo = '', $cTarget = '')
		{
			$cActionHTML = $this->oModule->makeAction( '', $cAction, $cParametros , $ncModo , $cAccessKey , $cTarget);
			if ( $cActionHTML  ) $this->cListActions .= '&nbsp;' . $cActionHTML ;
		}
	function getFieldString()
		{
			$cRet = "";
			foreach ( $this->aFields as $cKey  => $cValue )
			{
				if ( $cValue ) $cRet .= "&amp;$cKey=$cValue";
			}
			return substr( $cRet, 5);
		}
	function setFieldTitle( $bFieldTitle )
		{
			$this->bFieldTitle = $bFieldTitle;
		}
	function setOptions( $cOptions )
		{
			$this->cOptions = $cOptions;
		}
	function mergeOptions( $cOptions )
		{
			if ( $cOptions == '' ) return false;
			for ( $nIndex = 0; $nIndex < strlen($cOptions); $nIndex++ )
			{
				if ( $this->cOptions{$nIndex} == ''|| $this->cOptions{$nIndex} == ' ' ) $this->cOptions{$nIndex} = $cOptions{$nIndex};
			}
		}
	function addColumn ( $cName, $cField = '', $bOrderBy = false, $cWidth = "" )
		{
			$this->aColumns[] = array( $cName, $cField, $bOrderBy , $cWidth);
		}
	function setSummary ( $cSummary )
		{
			$this->cSummary = $cSummary;
		}
	function setRowActions( $nRowActions )
		{
			$this->nRowActions = $nRowActions;
		}
	function setTitle ( $cTitle )
		{
			$this->cTitle = $cTitle;
		}
	function Mlt ( &$oModule )
		{
			$this->oModule = &$oModule;
		// Toma por referencia la Base de datos del Modulo
			$this->oDatabase = &$oModule->oDatabase;
			$this->cClassContainer = getParam( PARAM_CONTAINER  , strtolower(get_class($this)) );
			$this->cOptions = getParam( PARAM_OPTIONS . '_' . $this->cClassContainer , ' ');
			$this->cUrlBase = replaceString( PARAM_CLASS, strtolower(get_class($this)),  $oModule->getThisUrl() );
			$this->cUrlBase = replaceString( PARAM_REFRESH, "action",  $this->cUrlBase );
			$this->cUrlBase = replaceString ( PARAM_CONTAINER, '', $this->cUrlBase);
			$nCalendarView = getParam( PARAM_CALENDARVIEW );
			if ( $nCalendarView ) $this->nCalendarView = $nCalendarView;
		// Crea el Objeto del Paginado
			$this->oPaging = new Paging( $this->cUrlBase , $this->cClassContainer );
			$this->oWhere = new BuildExpression();
		}
	function setFieldValue( $cField, $cValue )
		{
			return $this->aFields[$cField]->setValue($cValue);
		}
	function getFieldValue( $cField )
		{
			return $this->aFields[$cField]->getValue();
		}
	function getFieldArray()
		{
			return $this->aFields ;
		}
	function open()
		{
		}
	function makeListActions()
		{
		}
	function makeSelectionActions()
		{
		}
	function makeRowActions( $aRow )
		{
		}
	function makeColumn( &$aRow, $cName )
		{
			return false;
		}
	function makeRowProperties( $aRow  )
		{
		}
	function setOrderBy( $cOrderField, $bAscending = true)
		{
			$this->oPaging->setOrderBy($cOrderField, $bAscending);
		}
	function setNoPaging()
		{
			$this->oPaging->setNoPaging();
		}
	function setPage( $nFrom, $nTo )
		{
			$this->oPaging->setPage( $nFrom, $nTo );
		}
	function& setIndex( $nIndex, $nPosicion = TAB_TOP )
		{
			$this->nIndex = $nIndex;
			if ( empty($this->aTab[$nPosicion]) && $nIndex != INDEX_NONE )
			{
				$this->aTab[$nPosicion] = new Tab($this->cClassContainer, $nPosicion);
				$this->aTab[$nPosicion]->setUrl ( $this->cUrlBase );
			}
			switch( $this->nIndex)
			{
				case INDEX_ABC:
					$this->aTab[$nPosicion]->addTab ( "\\", "\\" );
					$aABC = array ( "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" );
					foreach( $aABC as $cLetra )
					{
						$this->aTab[$nPosicion]->addTab ( $cLetra, $cLetra );
					}
					break;
				case INDEX_WEEK:
					break;
				case INDEX_MONTH:
					break;
				case INDEX_USER:
					return $this->aTab[$nPosicion];
					break;
				case INDEX_NONE:
					unset( $this->aTab[$nPosicion] );
					break;
			}
		}
	function getIndex( $nPosicion = TAB_TOP )
		{
			$cValue = $this->aTab[$nPosicion]->getValue();
			return $cValue == "\\" ? "" : $cValue;
		}
	function makeIndex( $nPosicion = TAB_TOP  )
		{
			if ( empty($this->aTab[$nPosicion]) ) return "";
			$this->aTab[$nPosicion]->make();
		}
	function make( $cOptions = ''  )
		{
			$this->mergeOptions( $cOptions );
			$this->initialize();
			if ( $this->cOptions[4]  == 'C' ) $this->oPaging->setNoPaging();
			// Si no esta abierto el Recordset => lo Abre
			if ( !is_object($this->oRecordset) )
			{
				if ( $this->open() == false )
				{
					addMessage("No se pudo abrir la consulta");
					return false;
				}
			}
			// Arma las Acciones de la lista
			$this->makeListActions();
			// Arma las acciones de Multiselecion
			$this->makeSelectionActions();
			// Si el tipo es Listado o Directorio
			switch( $this->cOptions[4] )
			{
				case 'L':
					$this->makeListView();
					break;
				case 'D':
					$this->makeDirectoryView();
					break;
				case 'T':
					$this->makeTreeView();
					break;
				case 'C':
					$this->makeCalendarView();
					break;
				case 'M':
					$this->makeMapView();
					break;
				default:
					$this->makeListView();
			}
		}
	function getMltActions()
		{
			$cReturn = "";
			$aDatos = array();
			if ( MODO_AJAX == false ) return "";
			// Acciones
			$aLoopKey[] = 'L';
			if ( $this->cSelectionActions ) $aLoopKey[] = 'M';
			$aLoopKey[] = 'D';
			if ( $this->cOptions[3] == 'M' ) $cLoopKeyActual = 'M'; 
			else
			{
				$cLoopKeyActual = $this->cOptions[4];
				if ( $cLoopKeyActual[0] == 'C' ) $cLoopKeyActual .= $this->nCalendarView; 
			}
			if ( !($this->makeColumn ( &$aDatos, 'KeyTree' ) === false) ) $aLoopKey[] = 'T'; 
			if ( !($this->makeColumn ( &$aDatos, 'KeyDay' ) === false) )
			{
				$aLoopKey = array_merge( (array)$aLoopKey, array( 'C' . CALENDAR_MONTH, 'C' . CALENDAR_WEEK, 'C' . CALENDAR_DAY) );
			}
			$cLoopKey = $aLoopKey[ (array_search( $cLoopKeyActual , $aLoopKey) + 1) % count($aLoopKey) ];
			if ( $this->cOptions[3] == 'M' )
				{
					$cReturn .= '&nbsp;'. $this->oModule->makeLink( "javascript:invertirSeleccion( \"frmSelection\" ); return false;", 'accion3' , "Invertir seleccion", URL_IMAGES . "/check.gif", VENTANA_PRINCIPAL, ACCION_NORMAL, $this->cClassContainer  ) ;
					$cReturn .= '&nbsp;'. $this->cSelectionActions;
					$cOptions = DEFAULT_MAKE_LST;
					if ( $this->cOptions[2] == 'A' )
					{
						$cUrl = replaceString( PARAM_OPTIONS . '_' . $this->cClassContainer , $cOptions ,  $this->cUrlBase );
						$cReturn .= '&nbsp;'. $this->oModule->makeLink( $cUrl, 'accion3' , "Normal", URL_IMAGES . "/normal.gif", VENTANA_PRINCIPAL, ACCION_NORMAL, $this->cClassContainer , $cAccessKey) ;
					}
				} elseif ( $this->cSelectionActions != '' && $this->cOptions[2] == 'A' )
				{
					$cAccessKey = $cLoopKey == 'M' ? 'o' : '';
					$cOptions = $this->cOptions;
					$cOptions{3} = 'M';
					$cUrl = replaceString( PARAM_OPTIONS . '_' . $this->cClassContainer , $cOptions , $this->cUrlBase );
					$cReturn .= '&nbsp;'. $this->oModule->makeLink( $cUrl, 'accion3' , "Multiaccion", URL_IMAGES . "/multi.gif", VENTANA_PRINCIPAL, ACCION_NORMAL, $this->cClassContainer , $cAccessKey) ;
				}
			if ( $this->cOptions[2] == 'A' )
				{
				if ( $this->cOptions[4] != 'L' )
					{
						$cAccessKey = $cLoopKey == 'L' ? 'o' : '';
						$cUrl = replaceString( PARAM_OPTIONS . '_' . $this->cClassContainer , DEFAULT_MAKE_LST , $this->cUrlBase );
						$cReturn .= '&nbsp;'. $this->oModule->makeLink( $cUrl, 'accion3' , "Listado", URL_IMAGES . "/list.gif", VENTANA_PRINCIPAL, ACCION_NORMAL, $this->cClassContainer , $cAccessKey) ;
					}
				if ( $this->cOptions[4] != 'D' )
					{
						$cAccessKey = $cLoopKey == 'D' ? 'o' : '';
						$cUrl = replaceString( PARAM_OPTIONS . '_' . $this->cClassContainer , DEFAULT_MAKE_DIR , $this->cUrlBase );
						$cReturn .= '&nbsp;'. $this->oModule->makeLink( $cUrl, 'accion3' , "Directorio", URL_IMAGES . "/dir.gif", VENTANA_PRINCIPAL, ACCION_NORMAL, $this->cClassContainer , $cAccessKey) ;
					}
				if ( $this->cOptions[4] != 'T' && !($this->makeColumn ( &$aDatos, 'KeyTree' ) === false) )
					{
						$cAccessKey = $cLoopKey == 'T' ? 'o' : '';
						$cUrl = replaceString( PARAM_OPTIONS . '_' . $this->cClassContainer , DEFAULT_MAKE_TRE ,  $this->cUrlBase );
						$cReturn .= '&nbsp;'. $this->oModule->makeLink( $cUrl, 'accion3' , "Arbol", URL_IMAGES . "/tree.gif", VENTANA_PRINCIPAL, ACCION_NORMAL, $this->cClassContainer , $cAccessKey) ;
					}
				if ( !($this->makeColumn ( &$aDatos, 'KeyDay' ) === false) )
					{
						$cUrlBase = replaceString( PARAM_OPTIONS . '_' . $this->cClassContainer , DEFAULT_MAKE_CAL , $this->cUrlBase );
						// Vista del Mes
						$cAccessKey = $cLoopKey == 'C' . CALENDAR_MONTH ? 'o' : '';
						$cUrl = replaceString( PARAM_CALENDARVIEW, CALENDAR_MONTH , $cUrlBase );
						$cReturn .= '&nbsp;'. $this->oModule->makeLink( $cUrl, 'accion3' , "Mes", URL_IMAGES . "/mes.gif", VENTANA_PRINCIPAL, ACCION_NORMAL, $this->cClassContainer , $cAccessKey) ;
						if ( !($this->makeColumn ( &$aDatos, 'KeyFrom' ) === false) )
						{
							// Vista de la Semana
							$cAccessKey = $cLoopKey == 'C' . CALENDAR_WEEK ? 'o' : '';
							$cUrl = replaceString( PARAM_CALENDARVIEW, CALENDAR_WEEK ,  $cUrlBase );
							$cReturn .= '&nbsp;'. $this->oModule->makeLink( $cUrl, 'accion3' , "Semana", URL_IMAGES . "/semana.gif", VENTANA_PRINCIPAL, ACCION_NORMAL, $this->cClassContainer , $cAccessKey) ;
							// Vista del Dia
							$cAccessKey = $cLoopKey == 'C' . CALENDAR_DAY ? 'o' : '';
							$cUrl = replaceString( PARAM_CALENDARVIEW, CALENDAR_DAY , $cUrlBase );
							$cReturn .= '&nbsp;'. $this->oModule->makeLink( $cUrl, 'accion3' , "Dia", URL_IMAGES . "/dia.gif", VENTANA_PRINCIPAL, ACCION_NORMAL, $this->cClassContainer , $cAccessKey) ;
						}
					}
					// Accion de Salida de Impresiones
					$cUrl = replaceString( PARAM_METHOD , 'makeRptControl',  $this->cUrlBase);
					$cUrl =  $this->oModule->makeLink( $cUrl, 'accion3' , "Salidas", URL_IMAGES . "/impresora.gif", VENTANA_PRINCIPAL, ACCION_NORMAL, $this->cClassContainer . "_salida" ) ;
					$cUrl = replaceString( PARAM_REFRESH, 'class', $cUrl  );
					$cReturn = "&nbsp;<span id='" . $this->cClassContainer . "_salida'>".  $cUrl . "</span>" . $cReturn;
				}
			if ( $this->cOptions[1] != 'N' ) $cReturn .=  $this->cListActions;
			return $cReturn ;
		}
	function makeRptControl()
	{
		$cClassName = strtolower(get_class($this));
		$oInput = new InputList( "cFile");
		$oInput->setDirectory( $this->oModule->cPathRpt . "/" . $cClassName  );
		$cUrl = replaceString( PARAM_METHOD , 'makeRpt',  $this->cUrlBase) ;
		$cAction = replaceString( PARAM_REFRESH, 'class',  $cUrl) ;
		echo "<form target='_blank' id='frmSalidas' name='frmSalidas' style='display:inline' action='$cAction' method='post' >";
		echo $oInput->make() ;
		$cNombre = "Ver"; $cIcono = URL_IMAGES . "/ver.gif";
		echo "<input value='$cNombre ' alt='$cNombre ' name='submit' title='$cNombre'  type='image' src='$cIcono' />";
		$cNombre = "Agregar"; $cIcono = URL_IMAGES . "/agregar.gif";
		echo "<input value='$cNombre ' alt='$cNombre ' name='submit' title='$cNombre'  type='image' src='$cIcono' />";
		$cNombre = "Modificar"; $cIcono = URL_IMAGES . "/modificar.gif";
		echo "<input value='$cNombre ' alt='$cNombre ' name='submit' title='$cNombre'  type='image' src='$cIcono' />";
		echo "</form>";
	}
	function makeRpt()
	{
		switch( rtrim(ltrim( $_POST['submit'])) ) 
		{
			case "Modificar":
			case "Agregar":
				break;
			case "Ver":
				$oModBase =& loadModule("base");
				$oModBase->loadLibrary("reporte");
				$cFile = getParam("cFile");
				$cClassName = strtolower(get_class($this));
				$cTemplateCode= join(file(  $this->oModule->cPathRpt . "/" . $cClassName  . "/" . $cFile   ));
				$this->setOptionView('D') ;
				$this->oPaging->setNoPaging();
				$this->open();
				//$aDatos[]= $this->oRecordset->getMatrix();
				$this->initialize();
				$nRow = 0;
				$aDatos[0] = array();
				while ( $this->oRecordset->moveNext() )
				{
					foreach ( $this->aColumns as $aColumn )
					{
						$cValor =  ( $aColumn[1] != '' ) ? $this->oRecordset->aFields[$aColumn[1]] : $this->makeColumn( &$this->oRecordset->aFields, $aColumn[0] ) ;
						$aDatos[0][$nRow][$aColumn[0]] = $cValor ;
					}
					$nRow++;
				}
				echo parseTemplate($cTemplateCode, null, $aDatos, $this->oDatabase, $bParam );
			break;
		}
	}
	function isDirectory ()
		{
			return $this->cOptions[4] == 'D' ? true : false;
		}
	function isTree()
		{
			return $this->cOptions[4] == 'T' ? true : false;
		}
	function initialize()
		{
		}
	function expandNode ( $nKeyTree = '')
		{
		}
	function makeTreeView()
		{
		}
	function makeDirectoryView()
		{
		}
	function getTreeKey()
		{
		}
	function getDateRange()
		{
		}
	function makeCalendarView()
		{
		}
	function makeMapView()
		{
		}
	function makeListView()
		{
		}
	function getData()
		{
		}
	function makeMap()
		{
			$this->make( DEFAULT_MAKE_MAP );
		}
	function makeCal()
		{
			$this->make( DEFAULT_MAKE_CAL );
		}
	function makeMul()
		{
			$this->make( DEFAULT_MAKE_MUL );
		}
	function makeLst()
		{
			$this->make( DEFAULT_MAKE_LST );
		}
	function makeDir()
		{
			$this->make( DEFAULT_MAKE_DIR );
		}
	function makeSel()
		{
			$this->make( DEFAULT_MAKE_SEL );
		}
	function makeTab()
		{
			$this->oPaging->setNoPaging();
			$this->make( DEFAULT_MAKE_TAB );
		}
	function setOptionView($cOption)
		{
			$this->cOptions{4} = $cOption;
		}
	function getOptionView()
		{
			return $this->cOptions{4};
		}
	function setOptionsRowSelector ( $cOption ) 
		{
			$this->cOptions{3} = $cOption;
		}
	function getOptionsRowSelector () 
		{
			return $this->cOptions{3};
		}
	function setOptionsShowModes ( $cOption ) 
		{
			$this->cOptions{2} = $cOption;
		}
	function getOptionsShowModes () 
		{
			return $this->cOptions{2};
		}
	function setOptionsListAction ( $cOption ) 
		{
			$this->cOptions{1} = $cOption;
		}
	function getOptionsListAction () 
		{
			return $this->cOptions{1};
		}
	function setOptionsRowAction ( $cOption ) 
		{
			$this->cOptions{0} = $cOption;
		}
	function getOptionsRowAction () 
		{
			return $this->cOptions{0};
		}
	function setCalendarView( $nCalendarView ) 
		{
			$this->nCalendarView = $nCalendarView;
		}
	function getCalendarView() 
		{
			return $this->nCalendarView;
		}
	}
?>
